/**	
 * <br>
 * Copyright 2011 Chuan. All rights reserved.<br>
 * <br>			 
 * Package: com.chuan.mantu.utils <br>
 * FileName: DirUtil.java <br>
 * <br>
 * @version
 * @author javacyc@qq.com
 * @created 2012-11-20
 * @last Modified 
 * @history
 */

package com.chuan.mantu.utils;

import java.io.File;

import android.content.Context;
import android.os.Environment;

/**
 * {目录工具类}
 *  
 *  @author javacyc@qq.com
 *  @created 2012-11-20 下午03:50:52
 *  @lastModified       
 *  @history           
 */

public class DirUtil {

	 /**
	  * 
	  *  ｛判断SD卡是否存在｝
	  *  @return
	  *  @author javacyc@qq.com
	  *  @created 2012-11-20 下午03:53:43
	  *  @lastModified       
	  *  @history
	  */
	 private boolean hasSdcard() {
	     String status = Environment.getExternalStorageState();
	     if (status.equals(Environment.MEDIA_MOUNTED)) {
	         return true;
	     } else {
	         return false;
	     }
	 }
	
	 /**
	  * 
	  *  ｛创建目录｝
	  *  @param path
	  *  @author javacyc@qq.com
	  *  @created 2012-11-20 下午03:53:34
	  *  @lastModified       
	  *  @history
	  */
	 public void createPath(String path) {
	     File file = new File(path);
	     if (!file.exists()) {
	         file.mkdir();
	     }
	 }
	 
	 /**
	  * 
	  *  ｛创建根目录｝
	  *  @author javacyc@qq.com
	  *  @created 2012-11-20 下午04:03:51
	  *  @lastModified       
	  *  @history
	  */
	 public void createPicRootDir(Context context){
		 if(hasSdcard()){
			 createPath(Environment.getExternalStorageDirectory().getAbsolutePath() 
					 	+ Const.PATH_BACKLASH 
					 	+ Const.SDCARD_FILENAME);
		 }
	 }

	 /**
	  * 
	  *  ｛创建根目录下pic目录｝
	  *  @param context
	  *  @author javacyc@qq.com
	  *  @created 2012-11-20 下午04:08:21
	  *  @lastModified       
	  *  @history
	  */
	 public void createPicDir(Context context){
		 if(hasSdcard()){
			 createPath(Environment.getExternalStorageDirectory().getAbsolutePath() 
					 	+ Const.PATH_BACKLASH 
					 	+ Const.SDCARD_FILENAME
					 	+ Const.PATH_BACKLASH
					 	+ Const.PIC_ROOT_PATH);
		 }
	 }
	 
	 /**
	  * 
	  *  ｛创建类别文件夹｝
	  *  @param context
	  *  @param category 类别
	  *  @author javacyc@qq.com
	  *  @created 2012-11-20 下午04:55:22
	  *  @lastModified       
	  *  @history
	  */
	 public void createCategoryPicDir(Context context,String category){
		 if(hasSdcard()){
			 createPath(Environment.getExternalStorageDirectory().getAbsolutePath() 
					 	+ Const.PATH_BACKLASH 
					 	+ Const.SDCARD_FILENAME
					 	+ Const.PATH_BACKLASH
					 	+ Const.PIC_ROOT_PATH
					 	+ Const.PATH_BACKLASH
					 	+ category);
		 }
	 }
	 
}